<template>
<el-cascader :value="value" :options="options" @change="changeValue" clearable></el-cascader>
</template>

<script>
import { productToTree } from '@/utils/tools'
export default {
  name: "ProductCascader",
  props:{
    list:{
      type:Array,
      require:true
    },
    value:Number
  },
  computed:{
    options(){
      if (this.list.length > 0) {
        return productToTree(this.list)
      }
      return [];
    }
  },
  methods:{
    changeValue(val) {
      if (Array.isArray(val) && val.length>0) {
        this.$emit('input', val[2])
      } else {
        this.$emit('input',null)
      }
      this.$emit('change',val)
    }
  }
}
</script>
